package cc.autoapi.pucong.auto.flow.core.flow.execNode.exec;


import cc.autoapi.pucong.auto.flow.core.flow.execNode.entity.aop.TaskAopInfoVo;
import cc.autoapi.pucong.auto.flow.core.flow.execNode.entity.api.PropertiesVo;
import cc.autoapi.pucong.auto.flow.core.flow.execNode.entity.node.*;
import cc.autoapi.pucong.auto.flow.core.flow.execNode.entity.task.ApiExecResult;

import cc.autoapi.pucong.auto.flow.core.flow.execNode.exec.publish.ProcessExecApiPublish;
import cc.autoapi.pucong.auto.flow.core.flow.execNode.exec.publish.ProcessExecLogPublish;
import cc.autoapi.pucong.auto.flow.core.flow.execNode.exec.publish.ProcessExecNodePublish;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @description:
 * @author: cong.pu
 * @create: 2024-09-25 17:46
 **/
public class DataBus {
    private static ConcurrentHashMap<String, ApiExecResult> apiStatusMapSlots = new ConcurrentHashMap<>();
    private static ConcurrentHashMap<String, Map<String, Object>> queryParamMapSlots = new ConcurrentHashMap<>();
    private static ConcurrentHashMap<String, Map<String, String>> headerParamMapSlots = new ConcurrentHashMap<>();
    private static ConcurrentHashMap<String, Map<String, Object>> bodyParamMapSlots = new ConcurrentHashMap<>();
    private static ConcurrentHashMap<String, PropertiesVo> propertySlots = new ConcurrentHashMap<>();
    private static ConcurrentHashMap<String, List<TaskNode>> taskNodeListSlots = new ConcurrentHashMap<>();
    private static ConcurrentHashMap<String, List<TaskAopInfoVo>> taskAopListSlots = new ConcurrentHashMap<>();
    private static ConcurrentHashMap<String, List<ExecNode>> execNodeListSlots = new ConcurrentHashMap<>();
    private static ConcurrentHashMap<String, List<TaskNodeRelation>> taskNodeRelationListSlots = new ConcurrentHashMap<>();
    private static ConcurrentHashMap<String, List<TaskNodeParamOut>> taskNodeParamsOutListSlots = new ConcurrentHashMap<>();
    private static ConcurrentHashMap<String, List<TaskNodeParamIn>> taskNodeParamsInListSlots = new ConcurrentHashMap<>();

    private DataBus() {
    }

    public static void removeQueryParamMap(String key) {
        queryParamMapSlots.remove(key);
    }

    public static void removeHeaderParamMap(String key) {
        headerParamMapSlots.remove(key);
    }

    public static void removeBodyParamMap(String key) {
        bodyParamMapSlots.remove(key);
    }

    public static void removeExecNodeList(String key) {
        execNodeListSlots.remove(key);
    }

    public static void removeTaskNodeRelationList(String key) {
        taskNodeRelationListSlots.remove(key);
    }

    public static void removeTaskNodeList(String key) {
        taskNodeListSlots.remove(key);
    }

    public static void removeTaskAopList(String key) {
        taskAopListSlots.remove(key);
    }

    public static void removeTaskNodeParamsOutList(String key) {
        taskNodeParamsOutListSlots.remove(key);
    }

    public static void removeTaskNodeParamsInList(String key) {
        taskNodeParamsInListSlots.remove(key);
    }

    public static Map<String, Object> getQueryParams(String key) {
        return queryParamMapSlots.get(key);
    }

    public static Map<String, String> getHeaderParamMap(String key) {
        return headerParamMapSlots.get(key);
    }

    public static Map<String, Object> getBodyParamMap(String key) {
        return bodyParamMapSlots.get(key);
    }

    public static List<ExecNode> getExecNodeList(String key) {
        return execNodeListSlots.get(key);
    }


    public static List<TaskNode> getTaskNodeList(String key) {
        return taskNodeListSlots.get(key);
    }
    public static List<TaskAopInfoVo> getTaskAopList(String key) {
        return taskAopListSlots.get(key);
    }
    public static Set<String> getAllTaskAopKeyList() {
        return taskAopListSlots.keySet();
    }


    public static List<TaskNodeRelation> getTaskNodeRelationList(String key) {
        return taskNodeRelationListSlots.get(key);
    }

    public static List<TaskNodeParamIn> getTaskNodeParamsInList(String key) {
        return taskNodeParamsInListSlots.get(key);
    }

    public static List<TaskNodeParamOut> getTaskNodeParamsOutList(String key) {
        return taskNodeParamsOutListSlots.get(key);
    }

    public static ApiExecResult getApiStatus(String key) {
        return apiStatusMapSlots.get(key);
    }


    public static void setQueryParamMap(String key, Map<String, Object> queryParamMap) {
        queryParamMapSlots.put(key, queryParamMap);
    }

    public static void setHeaderParamMap(String key, Map<String, String> headerParamMap) {
        headerParamMapSlots.put(key, headerParamMap);
    }

    public static void setBodyParamMap(String key, Map<String, Object> bodyParamMap) {
        bodyParamMapSlots.put(key, bodyParamMap);
    }

    public static void setExecNodeList(String key, List<ExecNode> execNodeList) {
        execNodeListSlots.put(key, execNodeList);
    }

    public static void addExecNodeList(String key, ExecNode execNode) {
        List<ExecNode> execNodeList = execNodeListSlots.get(key);
        if (execNodeList == null) {
            execNodeList = new CopyOnWriteArrayList<>();
            setExecNodeList(key, execNodeList);
        }
        execNodeList.add(execNode);
    }

    public static void setTaskNodeList(String key, List<TaskNode> taskNodeList) {
        taskNodeListSlots.put(key, taskNodeList);
    }
    public static void setTaskAopList(String key, List<TaskAopInfoVo> taskAopInfoVos) {
        taskAopListSlots.put(key, taskAopInfoVos);
    }

    public static void setTaskNodeRelationList(String key, List<TaskNodeRelation> taskNodeRelationList) {
        taskNodeRelationListSlots.put(key, taskNodeRelationList);
    }

    public static void setExeNodeParamsOutList(String key, List<TaskNodeParamOut> taskNodeParamOutList) {
        taskNodeParamsOutListSlots.put(key, taskNodeParamOutList);
    }

    public static void setExeNodeParamsInList(String key, List<TaskNodeParamIn> taskNodeParamInList) {
        taskNodeParamsInListSlots.put(key, taskNodeParamInList);
    }

    public static void setApiStatus(String key, ApiExecResult apiExecResult) {
        apiStatusMapSlots.put(key, apiExecResult);
    }

    public static ProcessExecApiPublish getApiPublish() {
        return AutoFlow.apiPublish;
    }

    public static ProcessExecNodePublish getNodeExecPublish() {
        return AutoFlow.nodeExecPublish;
    }

    public static ProcessExecLogPublish getNodeLogPublish() {
        return AutoFlow.nodeLogPublish;
    }

    public static void setProperty(String key, PropertiesVo propertiesVo) {
        propertySlots.put(key, propertiesVo);
    }

    public static void removeProperty(String key) {
        propertySlots.remove(key);
    }

    public static PropertiesVo getProperty(String key) {
        return propertySlots.get(key);
    }
}
